package cn.wolfcode.mapper;

import cn.wolfcode.domain.Emp;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface EmpMapper {

    List<Emp> selAll(String name, Integer gender, Date begin, Date end);


    void deleteByIds(List<Integer> ids);

    @Insert("""
            insert into emp (username, name, image, gender, job, hiredate, dept_id, create_time, update_time)
            values (#{username},#{name},#{image},#{gender},#{job},#{hiredate},#{deptId},now(),now())
            """)
    void save(Emp emp);

    @Select("""
            select * from emp where id = #{id}
            """)
    Emp selectById(Long id);

    @Update("""
            update emp set username=#{username},name=#{name},image=#{image},gender=#{gender},
                           job=#{job},hiredate=#{hiredate},dept_id=#{deptId},update_time=now() 
                       where id=#{id}
            """)
    void update(Emp emp);

    @Select("""
            select * from emp where username=#{username} and password=#{password}
            """)
    Emp login(Emp emp);

    @Delete("""
            delete from emp where dept_id = #{id}
            """)
    void deleteByDeptId(Long id);
}
